﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AiRiZu.User;
using Arizu.Repository;
using System.Data;

namespace AiRiZu
{
    public partial class Contact1 : Common
    {
        public string TeSeimgurl = "images/default_user_pic.png";

        public string OwnerImgurl = "images/default_user_pic.png";

        public string RoomName = "";

        public string RoomAddr = "";

        public string RoomOwner_Name = "";

        public string RoomOwner_Adress = "";

        public string RoomOwner_School = "";

        public string RoomOwner_Work = "";

        public string You_Adress = "";

        public string You_School = "";

        public string You_Work = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            AirizuUser userDao = AirizuUser.CreateInstance();
            int userId = -1;
            if (Session["logId"] != null)
            {
                userId = int.Parse(Session["logId"].ToString());
                DataTable dt = userDao.GetUser(userId);

                if (dt.Rows.Count > 0)
                {
                    if (string.IsNullOrEmpty(dt.Rows[0]["Image"].ToString()))
                    {
                        TeSeimgurl = "images/default_user_pic.png";
                    }
                    else
                    {
                        TeSeimgurl = Constants.IMGURL + dt.Rows[0]["Image"].ToString();
                        
                    }
                    You_Adress = dt.Rows[0]["Adress"].ToString();
                    You_School = dt.Rows[0]["School"].ToString();
                    You_Work = dt.Rows[0]["Work"].ToString();
                }
            }

            if (Session["roomId"] != null)
            {
                AirizuRoom airizuRoom = AirizuRoom.CreateInstance();
                DataTable dt1 = airizuRoom.GetRoom(long.Parse(Session["roomId"].ToString()));
                if (dt1.Rows.Count > 0)
                {
                    long ownerId = long.Parse(dt1.Rows[0]["OwnerID"].ToString());
                    RoomName = dt1.Rows[0]["Name"].ToString();
                    RoomAddr = dt1.Rows[0]["Province"].ToString() + dt1.Rows[0]["City"].ToString() + dt1.Rows[0]["Area"].ToString() + dt1.Rows[0]["Adressdesc"].ToString();

                    DataTable dt = userDao.GetUser(ownerId);

                    if (dt.Rows.Count > 0)
                    {
                        if (string.IsNullOrEmpty(dt.Rows[0]["Image"].ToString()))
                        {
                            OwnerImgurl = "images/default_user_pic.png";
                        }
                        else
                        {
                            OwnerImgurl = Constants.IMGURL + dt.Rows[0]["Image"].ToString();
                            
                        }
                        RoomOwner_Adress = dt.Rows[0]["Adress"].ToString();
                        RoomOwner_School = dt.Rows[0]["School"].ToString();
                        RoomOwner_Work = dt.Rows[0]["Work"].ToString();
                        RoomOwner_Name = dt.Rows[0]["Xing"].ToString() + " "+dt.Rows[0]["Ming"].ToString();
                    }
                }
            }
        }
    }
}
